<template>
<div class="body">
<div class="login-page">
   <el-card class="box-card">
  <!-- slot="header" 具名插槽的旧语法，现已被淘汰 -->
  <!-- <div slot="header" class="clearfix"></div> -->
    <template #header>
      <div class="outer">
           <div class="pct"></div>
      </div>

    <!-- <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button> -->
    </template>

  <el-form ref="form" :model="form" :rules="rules">
  <el-form-item label="" prop="username">
    <el-input placeholder="" prefix-icon="el-icon-user-solid" type="username" v-model="form.username"></el-input>
  </el-form-item>
  <el-form-item label="" prop="password">
    <el-input placeholder="" prefix-icon="el-icon-lock"  type="password" v-model="form.password"></el-input>
  </el-form-item>

    <el-form-item style="text-align:right">
    <el-button type="primary" @click="onSubmit">登录</el-button>
    <el-button @click="$refs.form.resetFields()">重置</el-button>
  </el-form-item>
  </el-form>

</el-card>
</div>
</div>

</template>

<script>
export default {
  name: 'LoginIndex',
  data () {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: ['blur', 'change'] },
          { pattern: /^\w{5,10}$/, message: '长度在 5 到 10 个字符', trigger: ['blur', 'change'] }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 5, max: 10, message: '长度在 5 到 10 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    onSubmit () {
      // 兜底校验
      this.$refs.form.validate(async valid => {
        if (!valid) return
        // console.log('去登录')
        await this.$store.dispatch('user/loginAction', this.form)
        // 页面跳转去首页
        this.$router.push('/')
        // 提示用户成功
        this.$message.success('登录成功')
      })
    }
  }

}
</script>

<style lang="scss" scoped>
 .body {
  background-color: #354b68;
  width: 100%;
  height: 100vh;
  padding-top: 200px;
}
.el-card{
  margin: 0 auto;
}
.box-card {
  width:448px
}
.login-page{
   position: relative;
}
::v-deep .el-card__header{
  height: 108px;
  width: 448px;
  background-color: #fefefe;

.outer{
  width:152px;
  height:152px;
  background-color: #ffffff;
  border: solid 2px #eeeeee;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;

  position: absolute; /* 相对于父级容器进行定位 */
  margin-left: -50%; /* 设置负值的 margin-left，使内层盒子左边超出父容器的一半 */
  top: 0; /* 将内层盒子上边缘与父容器中心对齐 */
  left: 100%; /* 将内层盒子左边缘与父容器中心对齐 */
  transform: translate(-50%, -50%);

    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); /* 添加盒子阴影 */
   .pct{
  width:132px;
  height:132px;
  background-color: #eeeeee;
  border-radius: 50%;
  background-image: url('@/assets/logo.png');
  background-size: 100%;

}
}

}

</style>
